package com.zyh.stream;

import com.zyh.domain.Student;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author zyh
 * @Date 2024/8/16 14:08
 * @Description 映射 map
 */

public class StreamDemo5 {
    @Test
    public void test2() {
        List<Student> list = new ArrayList<>();
        list.add(new Student("zyh", "男", 18, 170.5));
        list.add(new Student("wy", "男", 20, 140.5));
        list.add(new Student("cxk", "女", 45, 120.5));
        list.add(new Student("dz", "女", 2, 180.5));
        list.add(new Student("zhangSan", "男", 13, 146.5));
        list.add(new Student("li4", "女", 56, 189.5));
        list.add(new Student("wang5", "男", 24, 110.5));
        //将所有学生的身高增加10厘米，并将长高之后的学生对象集合返回
        List<Student> list1 = list.stream().map(item -> {
            item.setHeight(item.getHeight() + 10.0);
            return item;
        }).collect(Collectors.toList());
        list1.forEach(System.out::println);
        System.out.println("-------------------");
        //获取集合中所有的男生的姓名返回新的集合
        List<String> list2 = list.stream().filter(item -> "男".equals(item.getSex())).map(item -> item.getName()).collect(Collectors.toList());
        list2.forEach(System.out::println);
    }


    @Test
    public void test1() {
        String[] strArr = {"java", "html", "python", "c++", "javascript", "vue", "c#"};
        List<String> list1 = Arrays.stream(strArr).map(String::toUpperCase).collect(Collectors.toList());
        list1.forEach(System.out::println);
    }
}
